package com.atcumt.bytedance;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class BT01 {

    /**
     * 数组中第 k 大的元素
     * 最小堆
     * 输入: [3,2,1,5,6,4] 和 k = 2
     * 输出: 5
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        Queue<Integer> minHeap = new PriorityQueue<>();
        for (int num : nums) {
            // 当前数字大于堆顶元素才会入堆
            if (minHeap.isEmpty() || minHeap.size() <= k || num > minHeap.peek()) {
                minHeap.offer(num);
            }
            if (minHeap.size() > k) {
                minHeap.poll();
            }
        }
        System.out.println(minHeap.peek());
    }
}
